package com.onemileshop.utils;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class UtiIO
{
   public static String ConvertStreamToString(InputStream is)
   {
	  BufferedReader reader = new BufferedReader(new InputStreamReader(is));
	  StringBuilder sb = new StringBuilder();
	  String line = null;
	  try
	  {
		 while ((line = reader.readLine()) != null)
		 {
			sb.append(line + " ");
		 }
	  }
	  catch (IOException e)
	  {
		 e.printStackTrace();
	  }
	  finally
	  {
		 try
		 {
			is.close();
		 }
		 catch (IOException e)
		 {
			e.printStackTrace();
		 }
	  }
	  return sb.toString();
   }

   public static String InputStreamToString(InputStream in) throws IOException
   {

	  StringBuffer out = new StringBuffer();
	  byte[] b = new byte[4096];
	  int n;
	  while ((n = in.read(b)) != -1)
	  {
		 out.append(new String(b, 0, n));
	  }
	  // Log.i("String的长度",new Integer(out.length()).toString());
	  return out.toString();
   }

   public static byte[] InputStreamToByte(InputStream is) throws IOException
   {
	  ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
	  int ch;
	  while ((ch = is.read()) != -1)
	  {
		 bytestream.write(ch);
	  }
	  byte imgdata[] = bytestream.toByteArray();
	  bytestream.close();
	  return imgdata;
   }
}
